import { Base } from "../../utils/base";
class Order extends Base{
  constructor(){
    super();
    this._storageKeyName = 'newOrder';
  }

   /*本地缓存 保存／更新*/
   execSetStorageSync(data) {
    wx.setStorageSync(this._storageKeyName, data);
}
     addOrder(data,callBack,ecallBack){
      var params = {
        url:'order/add/v2',
        data:{
          order:data
        },
        type:"post",
        sCallBack:function(res){ callBack && callBack(res.data) },
        eCallBack:function(err){ ecallBack && ecallBack(err.data)}
      }
      this.request(params);
     }

     payOrder(id,callBack,ecallBack){
      var params = {
        url:'pay/order/v2',
        data:{
          order_id:id
        },
        type:"post",
        sCallBack:function(res){ callBack && callBack(res.data) },
        eCallBack:function(err){ ecallBack && ecallBack(err.data)}
      }
      this.request(params);
     }

     payCallBack(order_no,callBack){
      var params = {
        url:'pay/wx?order_no='+order_no,
        sCallBack:function(res){ callBack && callBack(res.data) },
      }
      this.request(params);
     }

     getOrder(id,callBack,ecallBack){
      var params = {
        url:'order/get?id='+id,
        sCallBack:function(res){ callBack && callBack(res.data) },
        eCallBack:function(err){ ecallBack && ecallBack(err.data)}
      }
      this.request(params);
     }

        //检查是否有新订单生成
    hasNewOrder(){
      var flag = wx.getStorageSync(this._storageKeyName);
      return flag == true;
   }
}
export{Order}